package com.fjx.ai.service.impl;

import com.fjx.ai.service.AiChatHistoryService;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class AiChatHistoryServiceImpl implements AiChatHistoryService {

    private final Map<String,List<String>> conversationIdMap = new ConcurrentHashMap<>();
    @Override
    public void saveConversationId(String type, String conversationId) {
        List<String> strings = conversationIdMap.computeIfAbsent(type, k -> new ArrayList<>());
        strings.add(conversationId);
        conversationIdMap.put(type,strings);
    }

    @Override
    public List<String> getConversationId(String type) {
        if (type.isEmpty()){
            return Collections.emptyList();
        }
        if (conversationIdMap.containsKey(type)){
            return conversationIdMap.get(type);
        }
        return Collections.emptyList();
    }
}
